<?php

/**
 * ProductModel 模型
 * Class ProductModel
 */
class ProductModel extends BaseModel
{

    public $tableName = "product";
    public $errMsg = '';

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'product_name'  => $data['product_name'],
                'sub_name'      => isset($data['sub_name'])? $data['sub_name']: '',
                'cate_id'       => isset($data['cate_id'])? $data['cate_id']: 0,
                'unit_point'    => isset($data['unit_point'])? $data['unit_point']: 0,
                'sale_num'      => 0,
                'stock_num'     => isset($data['stock_num'])? $data['stock_num']: 0,
                'is_show'       => isset($data['is_show'])? $data['is_show']: 0,
                'is_hot'        => isset($data['is_hot'])? $data['is_hot']: 0,
                'cover_img'     => $data['cover_img'],
                'gallery_img'   => $data['gallery_img'],
                'content'       => $data['content'],
                'create_time'   => isset($data['create_time'])? $data['create_time']: time()
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }


}